package com.sm42.goodsController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sm42.baseController.BaseCrmpController;
import com.sm42.common.http.AxiosResult;
import com.sm42.common.page.PageBean;
import com.sm42.goodsEntity.Brand;
import com.sm42.goodsService.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("brand")
public class BrandController extends BaseCrmpController<Brand> {
    @Autowired
    private BrandService brandService;
/**
 * 根据商品品牌进行查询
 */
    @GetMapping("findBrandList")
    public AxiosResult<List<Brand>> findBrandList(String brand){
        return AxiosResult.success(brandService.findBrandList(brand));
    }
    /**
     * 根据id查询
     */
    @GetMapping("findBrandById")
    public AxiosResult<Brand> findBrandById(Long id){
        return AxiosResult.success(brandService.findBrandById(id));
    }
    /**
     * 根据id删除
     */
    @GetMapping("deleteBrandById")
    public AxiosResult deleteBrandById(Long id){
        return AxiosResult.success(brandService.deleteBrandById(id));
    }
    /**
     * 修改数据
     */
    @PostMapping("updateBrand")
    public AxiosResult updateBrand(Brand brand){
        return AxiosResult.success(brandService.updateBrand(brand));
    }
    /**
     * 新增数据
     */
    @GetMapping("addBrand")
    public AxiosResult addBrand(Brand brand){
        return AxiosResult.success(brandService.addBrand(brand));
    }
    /**
     * 模糊查询
     */
    @GetMapping("findSearch")
    public AxiosResult findSearch(Brand brand,Integer pageSize,Integer pageNum){
        Page<Object> page = PageHelper.startPage(pageNum, pageSize);
        brandService.findSearch(brand);
        return AxiosResult.success(PageBean.initData(page.getTotal(),page.getResult()));
    }
}
